<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>clock manual page - Tcl Built-In Commands</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tcl Commands</a> <small>&gt;</small> clock</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<DL>
<DD><A HREF="clock.htm#M2" NAME="L196">NAME</A>
<DL><DD>clock &mdash; Obtain and manipulate dates and times</DD></DL>
<DD><A HREF="clock.htm#M3" NAME="L197">SYNOPSIS</A>
<DL>
</DL>
<DD><A HREF="clock.htm#M4" NAME="L198">DESCRIPTION</A>
<DL class="description">
<DD><A HREF="clock.htm#M5" NAME="L199"><B>clock add</B> <I>timeVal</I> ?<I>count unit...</I>? ?<I>-option value</I>?</A>
<DD><A HREF="clock.htm#M6" NAME="L200"><B>clock clicks</B> ?<I>-option</I>?</A>
<DD><A HREF="clock.htm#M7" NAME="L201"><B>clock format</B> <I>timeVal</I> ?<I>-option value</I>...?</A>
<DD><A HREF="clock.htm#M8" NAME="L202"><B>clock microseconds</B></A>
<DD><A HREF="clock.htm#M9" NAME="L203"><B>clock milliseconds</B></A>
<DD><A HREF="clock.htm#M10" NAME="L204"><B>clock scan</B> <I>inputString</I> ?<I>-option value</I>...?</A>
<DD><A HREF="clock.htm#M11" NAME="L205"><B>clock seconds</B></A>
</DL>
<DD><A HREF="clock.htm#M12" NAME="L206">PARAMETERS</A>
<DL class="parameters">
<DD><A HREF="clock.htm#M13" NAME="L207"><I>count</I></A>
<DD><A HREF="clock.htm#M14" NAME="L208"><I>timeVal</I></A>
<DD><A HREF="clock.htm#M15" NAME="L209"><I>unit</I></A>
</DL>
<DD><A HREF="clock.htm#M16" NAME="L210">OPTIONS</A>
<DL class="options">
<DD><A HREF="clock.htm#M17" NAME="L211"><B>-base</B> time</A>
<DD><A HREF="clock.htm#M18" NAME="L212"><B>-format</B> format</A>
<DD><A HREF="clock.htm#M19" NAME="L213"><B>-gmt</B> boolean</A>
<DD><A HREF="clock.htm#M20" NAME="L214"><B>-locale</B> localeName</A>
<DD><A HREF="clock.htm#M21" NAME="L215"><B>-timezone</B> zoneName</A>
<OL class="options">
</OL>
</DL>
<DD><A HREF="clock.htm#M22" NAME="L216">CLOCK ARITHMETIC</A>
<DD><A HREF="clock.htm#M23" NAME="L217">HIGH RESOLUTION TIMERS</A>
<DD><A HREF="clock.htm#M24" NAME="L218">FORMATTING TIMES</A>
<DD><A HREF="clock.htm#M25" NAME="L219">SCANNING TIMES</A>
<OL class="scanning times">
</OL>
<OL class="scanning times">
</OL>
<DD><A HREF="clock.htm#M26" NAME="L220">FORMAT GROUPS</A>
<DL class="format groups">
<DD><A HREF="clock.htm#M27" NAME="L221"><B>%a</B></A>
<DD><A HREF="clock.htm#M28" NAME="L222"><B>%A</B></A>
<DD><A HREF="clock.htm#M29" NAME="L223"><B>%b</B></A>
<DD><A HREF="clock.htm#M30" NAME="L224"><B>%B</B></A>
<DD><A HREF="clock.htm#M31" NAME="L225"><B>%c</B></A>
<DD><A HREF="clock.htm#M32" NAME="L226"><B>%C</B></A>
<DD><A HREF="clock.htm#M33" NAME="L227"><B>%d</B></A>
<DD><A HREF="clock.htm#M34" NAME="L228"><B>%D</B></A>
<DD><A HREF="clock.htm#M35" NAME="L229"><B>%e</B></A>
<DD><A HREF="clock.htm#M36" NAME="L230"><B>%Ec</B></A>
<DD><A HREF="clock.htm#M37" NAME="L231"><B>%EC</B></A>
<DD><A HREF="clock.htm#M38" NAME="L232"><B>%EE</B></A>
<DD><A HREF="clock.htm#M39" NAME="L233"><B>%Ex</B></A>
<DD><A HREF="clock.htm#M40" NAME="L234"><B>%EX</B></A>
<DD><A HREF="clock.htm#M41" NAME="L235"><B>%Ey</B></A>
<DD><A HREF="clock.htm#M42" NAME="L236"><B>%EY</B></A>
<DD><A HREF="clock.htm#M43" NAME="L237"><B>%g</B></A>
<DD><A HREF="clock.htm#M44" NAME="L238"><B>%G</B></A>
<DD><A HREF="clock.htm#M45" NAME="L239"><B>%h</B></A>
<DD><A HREF="clock.htm#M46" NAME="L240"><B>%H</B></A>
<DD><A HREF="clock.htm#M47" NAME="L241"><B>%I</B></A>
<DD><A HREF="clock.htm#M48" NAME="L242"><B>%j</B></A>
<DD><A HREF="clock.htm#M49" NAME="L243"><B>%J</B></A>
<DD><A HREF="clock.htm#M50" NAME="L244"><B>%k</B></A>
<DD><A HREF="clock.htm#M51" NAME="L245"><B>%l</B></A>
<DD><A HREF="clock.htm#M52" NAME="L246"><B>%m</B></A>
<DD><A HREF="clock.htm#M53" NAME="L247"><B>%M</B></A>
<DD><A HREF="clock.htm#M54" NAME="L248"><B>%N</B></A>
<DD><A HREF="clock.htm#M55" NAME="L249"><B>%Od</B>, <B>%Oe</B>, <B>%OH</B>, <B>%OI</B>, <B>%Ok</B>, <B>%Ol</B>, <B>%Om</B>, <B>%OM</B>, <B>%OS</B>, <B>%Ou</B>, <B>%Ow</B>, <B>%Oy</B></A>
<DD><A HREF="clock.htm#M56" NAME="L250"><B>%p</B></A>
<DD><A HREF="clock.htm#M57" NAME="L251"><B>%P</B></A>
<DD><A HREF="clock.htm#M58" NAME="L252"><B>%Q</B></A>
<DD><A HREF="clock.htm#M59" NAME="L253"><B>%r</B></A>
<DD><A HREF="clock.htm#M60" NAME="L254"><B>%R</B></A>
<DD><A HREF="clock.htm#M61" NAME="L255"><B>%s</B></A>
<DD><A HREF="clock.htm#M62" NAME="L256"><B>%S</B></A>
<DD><A HREF="clock.htm#M63" NAME="L257"><B>%t</B></A>
<DD><A HREF="clock.htm#M64" NAME="L258"><B>%T</B></A>
<DD><A HREF="clock.htm#M65" NAME="L259"><B>%u</B></A>
<DD><A HREF="clock.htm#M66" NAME="L260"><B>%U</B></A>
<DD><A HREF="clock.htm#M67" NAME="L261"><B>%V</B></A>
<DD><A HREF="clock.htm#M68" NAME="L262"><B>%w</B></A>
<DD><A HREF="clock.htm#M69" NAME="L263"><B>%W</B></A>
<DD><A HREF="clock.htm#M70" NAME="L264"><B>%x</B></A>
<DD><A HREF="clock.htm#M71" NAME="L265"><B>%X</B></A>
<DD><A HREF="clock.htm#M72" NAME="L266"><B>%y</B></A>
<DD><A HREF="clock.htm#M73" NAME="L267"><B>%Y</B></A>
<DD><A HREF="clock.htm#M74" NAME="L268"><B>%z</B></A>
<DD><A HREF="clock.htm#M75" NAME="L269"><B>%Z</B></A>
<DD><A HREF="clock.htm#M76" NAME="L270"><B>%%</B></A>
<DD><A HREF="clock.htm#M77" NAME="L271"><B>%+</B></A>
</DL>
<DD><A HREF="clock.htm#M78" NAME="L272">TIME ZONES</A>
<OL class="time zones">
</OL>
<DD><A HREF="clock.htm#M79" NAME="L273">LOCALIZATION</A>
<DD><A HREF="clock.htm#M80" NAME="L274">FREE FORM SCAN</A>
<DL class="free form scan">
<DD><A HREF="clock.htm#M81" NAME="L275"><I>time</I></A>
<DD><A HREF="clock.htm#M82" NAME="L276"><I>date</I></A>
<DD><A HREF="clock.htm#M83" NAME="L277"><I>ISO 8601 point-in-time</I></A>
<DD><A HREF="clock.htm#M84" NAME="L278"><I>relative time</I></A>
</DL>
<DD><A HREF="clock.htm#M85" NAME="L279">SEE ALSO</A>
<DD><A HREF="clock.htm#M86" NAME="L280">KEYWORDS</A>
<DD><A HREF="clock.htm#M87" NAME="L281">COPYRIGHT</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
clock &mdash; Obtain and manipulate dates and times
<H3><A NAME="M3">SYNOPSIS</A></H3>
package require <B>Tcl 8.5</B><BR>
<B>clock add</B> <I>timeVal</I> ?<I>count unit...</I>? ?<I>-option value</I>?<BR>
<B>clock clicks</B> ?<I>-option</I>?<BR>
<B>clock format</B> <I>timeVal</I> ?<I>-option value</I>...?<BR>
<B>clock microseconds</B><BR>
<B>clock milliseconds</B><BR>
<B>clock scan</B> <I>inputString</I> ?<I>-option value</I>...?<BR>
<B>clock seconds</B><BR>
<H3><A NAME="M4">DESCRIPTION</A></H3>
The <B>clock</B> command performs several operations that obtain and
manipulate values that represent times.  The command supports several
subcommands that determine what action is carried out by the command.
<P>
<DL class="description">
<DT><A NAME="M5"><B>clock add</B> <I>timeVal</I> ?<I>count unit...</I>? ?<I>-option value</I>?</A><DD>
Adds a (possibly negative) offset to a time that is expressed as an
integer number of seconds.  See <B><A HREF="#M22">CLOCK ARITHMETIC</A></B> for a full description.
<P><DT><A NAME="M6"><B>clock clicks</B> ?<I>-option</I>?</A><DD>
If no <I>-option</I> argument is supplied, returns a high-resolution
time value as a system-dependent integer value.  The unit of the value
is system-dependent but should be the highest resolution clock available
on the system such as a CPU cycle counter.  See <B><A HREF="#M23">HIGH RESOLUTION TIMERS</A></B> for a full description.
<P>
If the <I>-option</I> argument is <B>-milliseconds</B>, then the command
is synonymous with <B>clock milliseconds</B> (see below).  This
usage is obsolete, and <B>clock milliseconds</B> is to be
considered the preferred way of obtaining a count of milliseconds.
<P>If the <I>-option</I> argument is <B>-microseconds</B>, then the command
is synonymous with <B>clock microseconds</B> (see below).  This
usage is obsolete, and <B>clock microseconds</B> is to be
considered the preferred way of obtaining a count of microseconds.
<P><DT><A NAME="M7"><B>clock format</B> <I>timeVal</I> ?<I>-option value</I>...?</A><DD>
Formats a time that is expressed as an integer number of seconds into a format
intended for consumption by users or external programs.
See <B><A HREF="#M24">FORMATTING TIMES</A></B> for a full description.
<P><DT><A NAME="M8"><B>clock microseconds</B></A><DD>
Returns the current time as an integer number of microseconds.  See <B><A HREF="#M23">HIGH RESOLUTION TIMERS</A></B> for a full description.
<P><DT><A NAME="M9"><B>clock milliseconds</B></A><DD>
Returns the current time as an integer number of milliseconds.  See <B><A HREF="#M23">HIGH RESOLUTION TIMERS</A></B> for a full description.
<P><DT><A NAME="M10"><B>clock scan</B> <I>inputString</I> ?<I>-option value</I>...?</A><DD>
Scans a time that is expressed as a character string and produces an
integer number of seconds.
See <B><A HREF="#M25">SCANNING TIMES</A></B> for a full description.
<P><DT><A NAME="M11"><B>clock seconds</B></A><DD>
Returns the current time as an integer number of seconds.
<P></DL>
<H4><A NAME="M12">PARAMETERS</A></H4>
<DL class="parameters">
<DT><A NAME="M13"><I>count</I></A><DD>
An integer representing a count of some unit of time.  See
<B><A HREF="#M22">CLOCK ARITHMETIC</A></B> for the details.
<P><DT><A NAME="M14"><I>timeVal</I></A><DD>
An integer value passed to the <B>clock</B> command that represents an
absolute time as a number of seconds from the <I>epoch time</I> of
1 January 1970, 00:00 UTC.  Note that the count of seconds does not
include any leap seconds; seconds are counted as if each UTC day has
exactly 86400 seconds.  Tcl responds to leap seconds by speeding or
slowing its clock by a tiny fraction for some minutes until it is
back in sync with UTC; its data model does not represent minutes that
have 59 or 61 seconds.
<P><DT><A NAME="M15"><I>unit</I></A><DD>
One of the words, <B>seconds</B>, <B>minutes</B>, <B>hours</B>,
<B>days</B>, <B>weeks</B>, <B>months</B>, or <B>years</B>, or
any unique prefix of such a word. Used in conjunction with <I>count</I>
to identify an interval of time, for example, <I>3 seconds</I> or
<I>1 year</I>.
<P></DL>
<H4><A NAME="M16">OPTIONS</A></H4>
<DL class="options">
<DT><A NAME="M17"><B>-base</B> time</A><DD>
Specifies that any relative times present in a <B>clock scan</B> command
are to be given relative to <I>time</I>.  <I>time</I> must be expressed as
a count of nominal seconds from the epoch time of 1 January 1970, 00:00 UTC.
<P><DT><A NAME="M18"><B>-format</B> format</A><DD>
Specifies the desired output format for <B>clock format</B> or the
expected input format for <B>clock scan</B>.  The <I>format</I> string consists
of any number of characters other than the per-cent sign
(&ldquo;<B>%</B>&rdquo;)
interspersed with any number of <I>format groups</I>, which are two-character
sequences beginning with the per-cent sign.  The permissible format groups,
and their interpretation, are described under <B><A HREF="#M26">FORMAT GROUPS</A></B>.
<P>
On <B>clock format</B>, the default format is
<P>
<PRE>%a %b %d %H:%M:%S %Z %Y</PRE>
<P>On <B>clock scan</B>, the lack of a <B>-format</B> option indicates that a
&ldquo;free format scan&rdquo;
is requested; see <B><A HREF="#M80">FREE FORM SCAN</A></B> for a description of what happens.
<P><DT><A NAME="M19"><B>-gmt</B> boolean</A><DD>
If <I>boolean</I> is true, specifies that a time specified to <B>clock add</B>,
<B>clock format</B> or <B>clock scan</B> should be processed in
UTC.  If <I>boolean</I> is false, the processing defaults to the local time
zone.  This usage is obsolete; the correct current usage is to
specify the UTC time zone with
&ldquo;<B>-timezone</B> <I>:UTC</I>&rdquo;
or any of the equivalent ways to specify it.
<P><DT><A NAME="M20"><B>-locale</B> localeName</A><DD>
Specifies that locale-dependent scanning and formatting (and date arithmetic
for dates preceding the adoption of the Gregorian calendar) is to be done in
the locale identified by <I>localeName</I>.  The locale name may be any of
the locales acceptable to the <B><A HREF="../TclCmd/msgcat.htm">msgcat</A></B> package, or it may be the special
name <I>system</I>, which represents the current locale of the process, or
the null string, which represents Tcl's default locale.
<P>
The effect of locale on scanning and formatting is discussed in the
descriptions of the individual format groups under <B><A HREF="#M26">FORMAT GROUPS</A></B>.
The effect of locale on clock arithmetic is discussed under
<B><A HREF="#M22">CLOCK ARITHMETIC</A></B>.
<P><DT><A NAME="M21"><B>-timezone</B> zoneName</A><DD>
Specifies that clock arithmetic, formatting, and scanning are to be done
according to the rules for the time zone specified by <I>zoneName</I>.
The permissible values, and their interpretation, are discussed under
<B><A HREF="#M78">TIME ZONES</A></B>.
On subcommands that expect a <B>-timezone</B> argument, the default
is to use the <I>current time zone</I>.  The current time zone is
determined, in order of preference, by:
<P>
<OL class="options">
<LI value="1">
the environment variable <B>TCL_TZ</B>.
<P><LI value="2">
the environment variable <B>TZ</B>.
<P><LI value="3">
on Windows systems, the time zone settings from the Control Panel.
<P></OL>
<P></DL>
<P>
If none of these is present, the C <B>localtime</B> and <B>mktime</B>
functions are used to attempt to convert times between local and
Greenwich.  On 32-bit systems, this approach is likely to have bugs,
particularly for times that lie outside the window (approximately the
years 1902 to 2037) that can be represented in a 32-bit integer.
<H3><A NAME="M22">CLOCK ARITHMETIC</A></H3>
The <B>clock add</B> command performs clock arithmetic on a value
(expressed as nominal seconds from the epoch time of 1 January 1970, 00:00 UTC)
given as its first argument.  The remaining arguments (other than the
possible <B>-timezone</B>, <B>-locale</B> and <B>-gmt</B> options)
are integers and keywords in alternation, where the keywords are chosen
from <B>seconds</B>, <B>minutes</B>, <B>hours</B>,
<B>days</B>, <B>weeks</B>, <B>months</B>, or <B>years</B>, or
any unique prefix of such a word.
<P>
Addition of seconds, minutes and hours is fairly straightforward;
the given time increment (times sixty for minutes, or 3600 for hours)
is simply added to the <I>timeVal</I> given
to the <B>clock add</B> command.  The result is interpreted as
a nominal number of seconds from the Epoch.
<P>
Surprising results
may be obtained when crossing a point at which a leap second is
inserted or removed; the <B>clock add</B> command simply ignores
leap seconds and therefore assumes that times come in sequence,
23:59:58, 23:59:59, 00:00:00.  (This assumption is handled by
the fact that Tcl's model of time reacts to leap seconds by speeding
or slowing the clock by a minuscule amount until Tcl's time
is back in step with the world.
<P>
The fact that adding and subtracting hours is defined in terms of
absolute time means that it will add fixed amounts of time in time zones
that observe summer time (Daylight Saving Time).  For example,
the following code sets the value of <B>x</B> to <B>04:00:00</B> because
the clock has changed in the interval in question.
<P>
<PRE>set s [<B>clock scan</B> {2004-10-30 05:00:00} &#92;
           -format {%Y-%m-%d %H:%M:%S} &#92;
           -timezone :America/New_York]
set a [<B>clock add</B> $s 24 hours -timezone :America/New_York]
set x [<B>clock format</B> $a &#92;
           -format {%H:%M:%S} -timezone :America/New_York]</PRE>
<P>
Adding and subtracting days and weeks is accomplished by converting
the given time to a calendar day and time of day in the appropriate
time zone and locale.  The requisite number of days (weeks are converted
to days by multiplying by seven) is added to the calendar day, and
the date and time are then converted back to a count of seconds from
the epoch time.
<P>
Adding and subtracting a given number of days across the point that
the time changes at the start or end of summer time (Daylight Saving Time)
results in the <I>same local time</I> on the day in question.  For
instance, the following code sets the value of <B>x</B> to <B>05:00:00</B>.
<P>
<PRE>set s [<B>clock scan</B> {2004-10-30 05:00:00} &#92;
           -format {%Y-%m-%d %H:%M:%S} &#92;
           -timezone :America/New_York]
set a [<B>clock add</B> $s 1 day -timezone :America/New_York]
set x [<B>clock format</B> $a &#92;
           -format {%H:%M:%S} -timezone :America/New_York]</PRE>
<P>
In cases of ambiguity, where the same local time happens twice
on the same day, the earlier time is used.  In cases where the conversion
yields an impossible time (for instance, 02:30 during the Spring
Daylight Saving Time change using US rules), the time is converted
as if the clock had not changed.  Thus, the following code
will set the value of <B>x</B> to <B>03:30:00</B>.
<P>
<PRE>set s [<B>clock scan</B> {2004-04-03 02:30:00} &#92;
           -format {%Y-%m-%d %H:%M:%S} &#92;
           -timezone :America/New_York]
set a [<B>clock add</B> $s 1 day -timezone :America/New_York]
set x [<B>clock format</B> $a &#92;
           -format {%H:%M:%S} -timezone :America/New_York]</PRE>
<P>
Adding a given number of days or weeks works correctly across the conversion
between the Julian and Gregorian calendars; the omitted days are skipped.
The following code sets <B>z</B> to <B>1752-09-14</B>.
<P>
<PRE>set x [<B>clock scan</B> 1752-09-02 -format %Y-%m-%d -locale en_US]
set y [<B>clock add</B> $x 1 day -locale en_US]
set z [<B>clock format</B> $y -format %Y-%m-%d -locale en_US]</PRE>
<P>
In the bizarre case that adding the given number of days yields a date
that does not exist because it falls within the dropped days of the
Julian-to-Gregorian conversion, the date is converted as if it was
on the Julian calendar.
<P>
Adding a number of months, or a number of years, is similar; it
converts the given time to a calendar date and time of day.  It then
adds the requisite number of months or years, and reconverts the resulting
date and time of day to an absolute time.
<P>
If the resulting date is impossible because the month has too few days
(for example, when adding 1 month to 31 January), the last day of the
month is substituted.  Thus, adding 1 month to 31 January will result in
28 February in a common year or 29 February in a leap year.
<P>
The rules for handling anomalies relating to summer time and to the
Gregorian calendar are the same when adding/subtracting months and
years as they are when adding/subtracting days and weeks.
<P>
If multiple <I>count unit</I> pairs are present on the command, they
are evaluated consecutively, from left to right.
<H3><A NAME="M23">HIGH RESOLUTION TIMERS</A></H3>
Most of the subcommands supported by the <B>clock</B> command deal with
times represented as a count of seconds from the epoch time, and this is the
representation that <B>clock seconds</B> returns.  There are three exceptions,
which are all intended for use where higher-resolution times are required.
<B>clock milliseconds</B> returns the count of milliseconds from the
epoch time, and <B>clock microseconds</B> returns the count of microseconds
from the epoch time. In addition, there is a <B>clock clicks</B> command
that returns a platform-dependent high-resolution timer.  Unlike
<B>clock seconds</B> and <B>clock milliseconds</B>, the value
of <B>clock clicks</B> is not guaranteed to be tied to any fixed
epoch; it is simply intended to be the most precise interval timer
available, and is intended only for relative timing studies such as
benchmarks.
<H3><A NAME="M24">FORMATTING TIMES</A></H3>
The <B>clock format</B> command produces times for display to a user
or writing to an external medium.  The command accepts times that are
expressed in seconds from the epoch time of 1 January 1970, 00:00 UTC,
as returned by <B>clock seconds</B>, <B>clock scan</B>, <B>clock add</B>,
<B><A HREF="../TclCmd/file.htm">file atime</A></B> or <B><A HREF="../TclCmd/file.htm">file mtime</A></B>.
<P>
If a <B>-format</B> option is present, the following argument is
a string that specifies how the date and time are to be formatted.
The string consists
of any number of characters other than the per-cent sign
(&ldquo;<B>%</B>&rdquo;)
interspersed with any number of <I>format groups</I>, which are two-character
sequences beginning with the per-cent sign.  The permissible format groups,
and their interpretation, are described under <B><A HREF="#M26">FORMAT GROUPS</A></B>.
<P>
If a <B>-timezone</B> option is present, the following
argument is a string that specifies the time zone in which the date and time
are to be formatted.  As an alternative to
&ldquo;<B>-timezone</B> <I>:UTC</I>&rdquo;,
the obsolete usage
&ldquo;<B>-gmt</B> <I>true</I>&rdquo;
may be used.  See
<B><A HREF="#M78">TIME ZONES</A></B> for the permissible variants for the time zone.
<P>
If a <B>-locale</B> option is present, the following argument is
a string that specifies the locale in which the time is to be formatted,
in the same format that is used for the <B><A HREF="../TclCmd/msgcat.htm">msgcat</A></B> package.  Note
that the default, if <B>-locale</B> is not specified, is the root locale
<B>{}</B> rather than the current locale.  The current locale may
be obtained by using <B>-locale</B> <B>current</B>.
In addition, some platforms support a <B>system</B> locale that
reflects the user's current choices.  For instance, on Windows, the
format that the user has selected from dates and times in the Control
Panel can be obtained by using the <B>system</B> locale.  On
platforms that do not define a user selection of date and time formats
separate from <B>LC_TIME</B>, <B>-locale</B> <B>system</B> is
synonymous with <B>-locale</B> <B>current</B>.
<H3><A NAME="M25">SCANNING TIMES</A></H3>
The <B>clock scan</B> command accepts times that are formatted as
strings and converts them to counts of seconds from the epoch time
of 1 January 1970, 00:00 UTC.  It normally takes a <B>-format</B>
option that is followed by a string describing
the expected format of the input.  (See
<B><A HREF="#M80">FREE FORM SCAN</A></B> for the effect of <B>clock scan</B>
without such an argument.)  The string consists of any number of
characters other than the per-cent sign
(&ldquo;<B>%</B>&rdquo;),
interspersed with any number of <I>format groups</I>, which are two-character
sequences beginning with the per-cent sign.  The permissible format groups,
and their interpretation, are described under <B><A HREF="#M26">FORMAT GROUPS</A></B>.
<P>
If a <B>-timezone</B> option is present, the following
argument is a string that specifies the time zone in which the date and time
are to be interpreted.  As an alternative to <B>-timezone</B> <I>:UTC</I>,
the obsolete usage <B>-gmt</B> <I>true</I> may be used.  See
<B><A HREF="#M78">TIME ZONES</A></B> for the permissible variants for the time zone.
<P>
If a <B>-locale</B> option is present, the following argument is
a string that specifies the locale in which the time is to be interpreted,
in the same format that is used for the <B><A HREF="../TclCmd/msgcat.htm">msgcat</A></B> package.  Note
that the default, if <B>-locale</B> is not specified, is the root locale
<B>{}</B> rather than the current locale.  The current locale may
be obtained by using <B>-locale</B> <B>current</B>.
In addition, some platforms support a <B>system</B> locale that
reflects the user's current choices.  For instance, on Windows, the
format that the user has selected from dates and times in the Control
Panel can be obtained by using the <B>system</B> locale.  On
platforms that do not define a user selection of date and time formats
separate from <B>LC_TIME</B>, <B>-locale</B> <B>system</B> is
synonymous with <B>-locale</B> <B>current</B>.
<P>
If a <B>-base</B> option is present, the following argument is
a time (expressed in seconds from the epoch time) that is used as
a <I>base time</I> for interpreting relative times.  If no
<B>-base</B> option is present, the base time is the current time.
<P>
Scanning of times in fixed format works by determining three things:
the date, the time of day, and the time zone.  These three are then
combined into a point in time, which is returned as the number of seconds
from the epoch.
<P>
Before scanning begins, the format string is preprocessed
to replace <B>%c</B>, <B>%Ec</B>, <B>%x</B>, <B>%Ex</B>,
<B>%X</B>. <B>%Ex</B>, <B>%r</B>, <B>%R</B>, <B>%T</B>,
<B>%D</B>, <B>%EY</B> and <B>%+</B> format groups with counterparts
that are appropriate to the current locale and contain none of the
above groups.  For instance, <B>%D</B> will (in the <B>en_US</B> locale)
be replaced with <B>%m/%d/%Y</B>.
<P>
The date is determined according to the fields that are present in the
preprocessed format string.  In order of preference:
<P>
<OL class="scanning times">
<LI value="1">
If the string contains a <B>%s</B> format group, representing
seconds from the epoch, that group is used to determine the date.
<P><LI value="2">
If the string contains a <B>%J</B> format group, representing
the Julian Day Number, that group is used to determine the date.
<P><LI value="3">
If the string contains a complete set of format groups specifying
century, year, month, and day of month; century, year, and day of year;
or ISO8601 fiscal year, week of year, and day of week; those groups are
combined and used to determine the date.  If more than one complete
set is present, the one at the rightmost position in the string is
used.
<P><LI value="4">
If the string lacks a century but contains a set of format
groups specifying year of century, month and day of month; year of
century and day of year; or two-digit ISO8601 fiscal year, week of year,
and day of week; those groups are
combined and used to determine the date.  If more than one complete
set is present, the one at the rightmost position in the string is
used.  The year is presumed to lie in the range 1938 to 2037 inclusive.
<P><LI value="5">
If the string entirely lacks any specification for the year
(or contains the year only on the locale's alternative calendar)
and contains a set of format groups specifying month and day of month,
day of year, or week of year and day of week, those groups are
combined and used to determine the date.  If more than one complete
set is present, the one at the rightmost position in the string is
used.  The year is determined by interpreting the base time in the given
time zone.
<P><LI value="6">
If the string contains none of the above sets, but has a day
of the month or day of the week, the day of the month or day of the week
are used to determine the date by interpreting the base time in the
given time zone and returning the given day of the current week or month.
(The week runs from Monday to Sunday, ISO8601-fashion.)  If both day
of month and day of week are present, the day of the month takes
priority.
<P><LI value="7">
If none of the above rules results in a usable date, the date
of the base time in the given time zone is used.
<P></OL>
<P>
The time is also determined according to the fields that are present in the
preprocessed format string.  In order of preference:
<P>
<OL class="scanning times">
<LI value="1">
If the string contains a <B>%s</B> format group, representing
seconds from the epoch, that group determines the time of day.
<P><LI value="2">
If the string contains either an hour on the 24-hour clock
or an hour on the 12-hour clock plus an AM/PM indicator, that hour determines
the hour of the day.  If the string further contains a group specifying
the minute of the hour, that group combines with the hour.  If the string
further contains a group specifying the second of the minute, that group
combines with the hour and minute.
<P><LI value="3">
If the string contains neither a <B>%s</B> format group nor
a group specifying the hour of the day, then midnight (<B>00:00</B>, the start
of the given date) is used.
The time zone is determined by either the <B>-timezone</B> or <B>-gmt</B>
options, or by using the current time zone.
<P></OL>
<P>
If a format string lacks a <B>%z</B> or <B>%Z</B> format group,
it is possible for the time to be ambiguous because it appears twice
in the same day, once without and once with Daylight Saving Time.
If this situation occurs, the first occurrence of the time is chosen.
(For this reason, it is wise to have the input string contain the
time zone when converting local times.  This caveat does not apply to
UTC times.)
<P>
If the interpretation of the groups yields an impossible time because
a field is out of range, enough of that field's unit will be added to
or subtracted from the time to bring it in range. Thus, if attempting to
scan or format day 0 of the month, one day will be subtracted from day
1 of the month, yielding the last day of the previous month.
<P>
If the interpretation of the groups yields an impossible time because
a Daylight Saving Time change skips over that time, or an ambiguous
time because a Daylight Saving Time change skips back so that the clock
observes the given time twice, and no time zone specifier (<B>%z</B>
or <B>%Z</B>) is present in the format, the time is interpreted as
if the clock had not changed.
<H3><A NAME="M26">FORMAT GROUPS</A></H3>
The following format groups are recognized by the <B>clock scan</B> and
<B>clock format</B> commands.
<P>
<DL class="format groups">
<DT><A NAME="M27"><B>%a</B></A><DD>
On output, produces an abbreviation (<I>e.g.,</I> <B>Mon</B>) for the day
of the week in the given locale.  On input, matches the name of the day
of the week in the given locale (in either abbreviated or full form, or
any unique prefix of either form).
<P><DT><A NAME="M28"><B>%A</B></A><DD>
On output, produces the full name (<I>e.g.,</I> <B>Monday</B>) of the day
of the week in the given locale.  On input, matches the name of the day
of the week in the given locale (in either abbreviated or full form, or
any unique prefix of either form).
<P><DT><A NAME="M29"><B>%b</B></A><DD>
On output, produces an abbreviation (<I>e.g.,</I> <B>Jan</B>) for the name
of the month in the given locale.  On input, matches the name of the month
in the given locale (in either abbreviated or full form, or
any unique prefix of either form).
<P><DT><A NAME="M30"><B>%B</B></A><DD>
On output, produces the full name (<I>e.g.,</I> <B>January</B>)
of the month in the given locale.  On input, matches the name of the month
in the given locale (in either abbreviated or full form, or
any unique prefix of either form).
<P><DT><A NAME="M31"><B>%c</B></A><DD>
On output, produces a localized representation of date and time of day;
the localized representation is expected to use the Gregorian calendar.
On input, matches whatever <B>%c</B> produces.
<P><DT><A NAME="M32"><B>%C</B></A><DD>
On output, produces the number of the century in Indo-Arabic numerals.
On input, matches one or two digits, possibly with leading whitespace,
that are expected to be the number of the century.
<P><DT><A NAME="M33"><B>%d</B></A><DD>
On output, produces the number of the day of the month, as two decimal
digits.  On input, matches one or two digits, possibly with leading
whitespace, that are expected to be the number of the day of the month.
<P><DT><A NAME="M34"><B>%D</B></A><DD>
This format group is synonymous with <B>%m/%d/%Y</B>.  It should be
used only in exchanging data within the <B>en_US</B> locale, since
other locales typically do not use this order for the fields of the date.
<P><DT><A NAME="M35"><B>%e</B></A><DD>
On output, produces the number of the day of the month, as one or
two decimal digits (with a leading blank for one-digit dates).
On input, matches one or two digits, possibly with leading
whitespace, that are expected to be the number of the day of the month.
<P><DT><A NAME="M36"><B>%Ec</B></A><DD>
On output, produces a locale-dependent representation of the date and
time of day in the locale's alternative calendar.  On input, matches
whatever <B>%Ec</B> produces.  The locale's alternative calendar need not
be the Gregorian calendar.
<P><DT><A NAME="M37"><B>%EC</B></A><DD>
On output, produces a locale-dependent name of an era in the locale's
alternative calendar.  On input, matches the name of the era or any
unique prefix.
<P><DT><A NAME="M38"><B>%EE</B></A><DD>
On output, produces the string <B>B.C.E.</B> or <B>C.E.</B>, or a
string of the same meaning in the locale, to indicate whether <B>%Y</B> refers
to years before or after Year 1 of the Common Era.  On input, accepts
the string <B>B.C.E.</B>, <B>B.C.</B>, <B>C.E.</B>, <B>A.D.</B>, or the
abbreviation appropriate to the current locale, and uses it to fix
whether <B>%Y</B> refers to years before or after Year 1 of the
Common Era.
<P><DT><A NAME="M39"><B>%Ex</B></A><DD>
On output, produces a locale-dependent representation of the date
in the locale's alternative calendar.  On input, matches
whatever <B>%Ex</B> produces.  The locale's alternative calendar need not
be the Gregorian calendar.
<P><DT><A NAME="M40"><B>%EX</B></A><DD>
On output, produces a locale-dependent representation of the
time of day in the locale's alternative numerals.  On input, matches
whatever <B>%EX</B> produces.
<P><DT><A NAME="M41"><B>%Ey</B></A><DD>
On output, produces a locale-dependent number of the year of the era
in the locale's alternative calendar and numerals.  On input, matches
such a number.
<P><DT><A NAME="M42"><B>%EY</B></A><DD>
On output, produces a representation of the year in the locale's
alternative calendar and numerals.  On input, matches what <B>%EY</B>
produces.  Often synonymous with <B>%EC%Ey</B>.
<P><DT><A NAME="M43"><B>%g</B></A><DD>
On output, produces a two-digit year number suitable for use with
the week-based ISO8601 calendar; that is, the year number corresponds
to the week number produced by <B>%V</B>.  On input, accepts such
a two-digit year number, possibly with leading whitespace.
<P><DT><A NAME="M44"><B>%G</B></A><DD>
On output, produces a four-digit year number suitable for use with
the week-based ISO8601 calendar; that is, the year number corresponds
to the week number produced by <B>%V</B>.  On input, accepts such
a four-digit year number, possibly with leading whitespace.
<P><DT><A NAME="M45"><B>%h</B></A><DD>
This format group is synonymous with <B>%b</B>.
<P><DT><A NAME="M46"><B>%H</B></A><DD>
On output, produces a two-digit number giving the hour of the day
(00-23) on a 24-hour clock.  On input, accepts such a number.
<P><DT><A NAME="M47"><B>%I</B></A><DD>
On output, produces a two-digit number giving the hour of the day
(12-11) on a 12-hour clock.  On input, accepts such a number.
<P><DT><A NAME="M48"><B>%j</B></A><DD>
On output, produces a three-digit number giving the day of the year
(001-366).  On input, accepts such a number.
<P><DT><A NAME="M49"><B>%J</B></A><DD>
On output, produces a string of digits giving the Julian Day Number.
On input, accepts a string of digits and interprets it as a Julian Day Number.
The Julian Day Number is a count of the number of calendar days
that have elapsed since 1 January, 4713 BCE of the proleptic
Julian calendar.  The epoch time of 1 January 1970 corresponds
to Julian Day Number 2440588.
<P><DT><A NAME="M50"><B>%k</B></A><DD>
On output, produces a one- or two-digit number giving the hour of the day
(0-23) on a 24-hour clock.  On input, accepts such a number.
<P><DT><A NAME="M51"><B>%l</B></A><DD>
On output, produces a one- or two-digit number giving the hour of the day
(12-11) on a 12-hour clock.  On input, accepts such a number.
<P><DT><A NAME="M52"><B>%m</B></A><DD>
On output, produces the number of the month (01-12) with exactly two
digits.  On input, accepts two digits and interprets them as the number
of the month.
<P><DT><A NAME="M53"><B>%M</B></A><DD>
On output, produces the number of the minute of the hour (00-59)
with exactly two digits.  On input, accepts two digits and interprets them
as the number of the minute of the hour.
<P><DT><A NAME="M54"><B>%N</B></A><DD>
On output, produces the number of the month (1-12) with one or two digits,
and a leading blank for one-digit dates.
On input, accepts one or two digits, possibly with leading whitespace,
and interprets them as the number of the month.
<P><DT><A NAME="M55"><B>%Od</B>, <B>%Oe</B>, <B>%OH</B>, <B>%OI</B>, <B>%Ok</B>, <B>%Ol</B>, <B>%Om</B>, <B>%OM</B>, <B>%OS</B>, <B>%Ou</B>, <B>%Ow</B>, <B>%Oy</B></A><DD>
All of these format groups are synonymous with their counterparts
without the
&ldquo;<B>O</B>&rdquo;,
except that the string is produced and parsed in the
locale-dependent alternative numerals.
<P><DT><A NAME="M56"><B>%p</B></A><DD>
On output, produces an indicator for the part of the day, <B>AM</B>
or <B>PM</B>, appropriate to the given locale.  If the script of the
given locale supports multiple letterforms, lowercase is preferred.
On input, matches the representation <B>AM</B> or <B>PM</B> in
the given locale, in either case.
<P><DT><A NAME="M57"><B>%P</B></A><DD>
On output, produces an indicator for the part of the day, <B>am</B>
or <B>pm</B>, appropriate to the given locale.  If the script of the
given locale supports multiple letterforms, uppercase is preferred.
On input, matches the representation <B>AM</B> or <B>PM</B> in
the given locale, in either case.
<P><DT><A NAME="M58"><B>%Q</B></A><DD>
This format group is reserved for internal use within the Tcl library.
<P><DT><A NAME="M59"><B>%r</B></A><DD>
On output, produces a locale-dependent time of day representation on a
12-hour clock. On input, accepts whatever <B>%r</B> produces.
<P><DT><A NAME="M60"><B>%R</B></A><DD>
On output, the time in 24-hour notation (%H:%M). For a version
including the seconds, see <B>%T</B> below. On input, accepts whatever
<B>%R</B> produces.
<P><DT><A NAME="M61"><B>%s</B></A><DD>
On output, simply formats the <I>timeVal</I> argument as a decimal
integer and inserts it into the output string.  On input, accepts
a decimal integer and uses is as the time value without any further
processing. Since <B>%s</B> uniquely determines a point in time, it
overrides all other input formats.
<P><DT><A NAME="M62"><B>%S</B></A><DD>
On output, produces a two-digit number of the second of the minute
(00-59). On input, accepts two digits and uses them as the second of the
minute.
<P><DT><A NAME="M63"><B>%t</B></A><DD>
On output, produces a TAB character. On input, matches a TAB character.
<P><DT><A NAME="M64"><B>%T</B></A><DD>
Synonymous with <B>%H:%M:%S</B>.
<P><DT><A NAME="M65"><B>%u</B></A><DD>
On output, produces the number of the day of the week
(<B>1</B><font size="+1">&rarr;</font>Monday, <B>7</B><font size="+1">&rarr;</font>Sunday). On input, accepts a single digit and
interprets it as the day of the week. Sunday may be either <B>0</B> or
<B>7</B>.
<P><DT><A NAME="M66"><B>%U</B></A><DD>
On output, produces the ordinal number of the week of the year
(00-53). The first Sunday of the year is the first day of week 01. On
input accepts two digits which are otherwise ignored. This format
group is never used in determining an input date.  This interpretation
of the week of the year was once common in US banking but is now
largely obsolete.  See <B>%V</B> for the ISO8601 week number.
<P><DT><A NAME="M67"><B>%V</B></A><DD>
On output, produces the number of the ISO8601 week as a two digit
number (01-53). Week 01 is the week containing January 4; or the first
week of the year containing at least 4 days; or the week containing
the first Thursday of the year (the three statements are
equivalent). Each week begins on a Monday. On input, accepts the
ISO8601 week number.
<P><DT><A NAME="M68"><B>%w</B></A><DD>
On output, produces the ordinal number of the day of the week
(Sunday==0; Saturday==6).  On input, accepts a single digit and
interprets it as the day of the week; Sunday may be represented as
either 0 or 7.  Note that <B>%w</B> is not the ISO8601 weekday number,
which is produced and accepted by <B>%u</B>.
<P><DT><A NAME="M69"><B>%W</B></A><DD>
On output, produces a week number (00-53) within the year; week 01
begins on the first Monday of the year. On input, accepts two digits,
which are otherwise ignored. This format group is never used in
determining an input date.  It is not the ISO8601 week number; that
week is produced and accepted by <B>%V</B>.
<P><DT><A NAME="M70"><B>%x</B></A><DD>
On output, produces the date in a locale-dependent representation. On
input, accepts whatever <B>%x</B> produces and is used to determine
calendar date.
<P><DT><A NAME="M71"><B>%X</B></A><DD>
On output, produces the time of day in a locale-dependent
representation. On input, accepts whatever <B>%X</B> produces and is used
to determine time of day.
<P><DT><A NAME="M72"><B>%y</B></A><DD>
On output, produces the two-digit year of the century. On input,
accepts two digits, and is used to determine calendar date. The
date is presumed to lie between 1938 and 2037 inclusive. Note
that <B>%y</B> does not yield a year appropriate for use with the ISO8601
week number <B>%V</B>; programs should use <B>%g</B> for that purpose.
<P><DT><A NAME="M73"><B>%Y</B></A><DD>
On output, produces the four-digit calendar year. On input,
accepts four digits and may be used to determine calendar date. Note
that <B>%Y</B> does not yield a year appropriate for use with the ISO8601
week number <B>%V</B>; programs should use <B>%G</B> for that purpose.
<P><DT><A NAME="M74"><B>%z</B></A><DD>
On output, produces the current time zone, expressed in hours and
minutes east (+hhmm) or west (-hhmm) of Greenwich. On input, accepts a
time zone specifier (see <B><A HREF="#M78">TIME ZONES</A></B> below) that will be used to
determine the time zone.
<P><DT><A NAME="M75"><B>%Z</B></A><DD>
On output, produces the current time zone's name, possibly
translated to the given locale. On input, accepts a time zone
specifier (see <B><A HREF="#M78">TIME ZONES</A></B> below) that will be used to determine the
time zone. This option should, in general, be used on input only when
parsing RFC822 dates. Other uses are fraught with ambiguity; for
instance, the string <B>BST</B> may represent British Summer Time or
Brazilian Standard Time. It is recommended that date/time strings for
use by computers use numeric time zones instead.
<P><DT><A NAME="M76"><B>%%</B></A><DD>
On output, produces a literal
&ldquo;<B>%</B>&rdquo;
character. On input, matches a literal
&ldquo;<B>%</B>&rdquo;
character.
<P><DT><A NAME="M77"><B>%+</B></A><DD>
Synonymous with
&ldquo;<B>%a %b %e %H:%M:%S %Z %Y</B>&rdquo;.
<P></DL>
<H3><A NAME="M78">TIME ZONES</A></H3>
When the <B>clock</B> command is processing a local time, it has several
possible sources for the time zone to use.  In order of preference, they
are:
<P>
<OL class="time zones">
<LI value="1">
A time zone specified inside a string being parsed and matched by a <B>%z</B>
or <B>%Z</B> format group.
<P><LI value="2">
A time zone specified with the <B>-timezone</B> option to the <B>clock</B>
command (or, equivalently, by <B>-gmt</B> <B>1</B>).
<P><LI value="3">
A time zone specified in an environment variable <B>TCL_TZ</B>.
<P><LI value="4">
A time zone specified in an environment variable <B>TZ</B>.
<P><LI value="5">
The local time zone from the Control Panel on Windows systems.
<P><LI value="6">
The C library's idea of the local time zone, as defined by the
<B>mktime</B> and <B>localtime</B> functions.
<P></OL>
<P>
In case [1] <I>only,</I> the string is tested to see if it is one
of the strings:
<P>
<PRE>gmt     ut      utc     bst     wet     wat     at
 nft     nst     ndt     ast     adt     est     edt
 cst     cdt     mst     mdt     pst     pdt     yst
 ydt     hst     hdt     cat     ahst    nt      idlw
 cet     cest    met     mewt    mest    swt     sst
 eet     eest    bt      it      zp4     zp5     ist
 zp6     wast    wadt    jt      cct     jst     cast
 cadt    east    eadt    gst     nzt     nzst    nzdt
 idle</PRE>
<P>
If it is a string in the above list, it designates a known
time zone, and is interpreted as such.
<P>
For time zones in case [1] that do not match any of the above strings,
and always for cases [2]-[6], the following rules apply.
<P>
If the time zone begins with a colon, it is one of a
standardized list of names like <B>:America/New_York</B>
that give the rules for various locales.  A complete list
of the location names is too lengthy to be listed here.
On most Tcl installations, the definitions of the locations
are to be found in named files in the directory
&ldquo;<I>/no_backup/tools/lib/tcl8.5/clock/tzdata</I>&rdquo;.
On some Unix systems, these files are omitted, and the definitions are
instead obtained from system files in
&ldquo;<I>/usr/share/zoneinfo</I>&rdquo;,
&ldquo;<I>/usr/share/lib/zoneinfo</I>&rdquo;
or
&ldquo;<I>/usr/local/etc/zoneinfo</I>&rdquo;.
As a special case, the name <B>:localtime</B> refers to
the local time zone as defined by the C library.
<P>
A time zone string consisting of a plus or minus sign followed by
four or six decimal digits is interpreted as an offset in
hours, minutes, and seconds (if six digits are present) from
UTC.  The plus sign denotes a sign east of Greenwich;
the minus sign one west of Greenwich.
<P>
A time zone string conforming to the Posix specification of the <B>TZ</B>
environment variable will be recognized.  The specification
may be found at
<I><A HREF="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html">http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html</A></I>.
<P>
If the Posix time zone string contains a DST (Daylight Savings Time)
part, but doesn't contain a rule stating when DST starts or ends,
then default rules are used. For Timezones with an offset between 0
and +12, the current European/Russian rules are used, otherwise the
current US rules are used. In Europe (offset +0 to +2) the switch
to summertime is done each last Sunday in March at 1:00 GMT, and
the switch back is each last Sunday in October at 2:00 GMT. In
Russia (offset +3 to +12), the switch dates are the same, only
the switch to summertime is at 2:00 local time, and the switch
back is at 3:00 local time in all time zones. The US switch to
summertime takes place each second Sunday in March at 2:00 local
time, and the switch back is each first Sunday in November at
3:00 local time. These default rules mean that in all European,
Russian and US (or compatible) time zones, DST calculations will
be correct for dates in 2007 and later, unless in the future the
rules change again.
<P>
Any other time zone string is processed by prefixing a colon and attempting
to use it as a location name, as above.
<H3><A NAME="M79">LOCALIZATION</A></H3>
Developers wishing to localize the date and time formatting and parsing
are referred to <I><A HREF="http://tip.tcl.tk/173">http://tip.tcl.tk/173</A></I> for a
specification.
<H3><A NAME="M80">FREE FORM SCAN</A></H3>
If the <B>clock scan</B> command is invoked without a <B>-format</B>
option, then it requests a <I>free-form scan.</I>  <I>
This form of scan is deprecated.</I>  The reason for the deprecation
is that there are too many ambiguities. (Does the string
&ldquo;2000&rdquo;
represent a year, a time of day, or a quantity?)  No set of rules
for interpreting free-form dates and times has been found to
give unsurprising results in all cases.
<P>
If free-form scan is used, only the <B>-base</B> and <B>-gmt</B>
options are accepted.  The <B>-timezone</B> and <B>-locale</B>
options will result in an error if <B>-format</B> is not supplied.
<P>
For the benefit of users who need to understand legacy code that
uses free-form scan, the documentation for how free-form scan
interprets a string is included here:
<P>
If only a time is
specified, the current date is assumed.  If the <I>inputString</I>
does not contain a
time zone mnemonic, the local time zone is assumed, unless the <B>-gmt</B>
argument is true, in which case the clock value is calculated assuming
that the specified time is relative to Greenwich Mean Time.
<B>-gmt</B>, if specified, affects only the computed time value; it does not
impact the interpretation of <B>-base</B>.
<P>
If the <B>-base</B> flag is specified, the next argument should contain
an integer clock value.  Only the date in this value is used, not the
time.  This is useful for determining the time on a specific day or
doing other date-relative conversions.
<P>
The <I>inputString</I> argument consists of zero or more specifications of the
following form:
<P>
<DL class="free form scan">
<DT><A NAME="M81"><I>time</I></A><DD>
A time of day, which is of the form: <B>hh?:mm?:ss?? ?meridian? ?zone?</B>
or <B>hhmm ?meridian? ?zone?</B>
If no meridian is specified, <B>hh</B> is interpreted on
a 24-hour clock.
<P><DT><A NAME="M82"><I>date</I></A><DD>
A specific month and day with optional year.  The
acceptable formats are
&ldquo;<B>mm/dd</B>?<B>/yy</B>?&rdquo;,
&ldquo;<B>monthname dd</B>?<B>, yy</B>?&rdquo;,
&ldquo;<B>day, dd monthname </B>?<B>yy</B>?&rdquo;,
&ldquo;<B>dd monthname yy</B>&rdquo;,
&ldquo;?<B>CC</B>?<B>yymmdd</B>&rdquo;,
and
&ldquo;<B>dd-monthname-</B>?<B>CC</B>?<B>yy</B>&rdquo;.
The default year is the current year.  If the year is less
than 100, we treat the years 00-68 as 2000-2068 and the years 69-99
as 1969-1999.  Not all platforms can represent the years 38-70, so
an error may result if these years are used.
<P><DT><A NAME="M83"><I>ISO 8601 point-in-time</I></A><DD>
An ISO 8601 point-in-time specification, such as
&ldquo;<I>CCyymmdd</I><B>T</B><I>hhmmss</I>,&rdquo;
where <B>T</B> is the literal
&ldquo;T&rdquo;,
&ldquo;<I>CCyymmdd hhmmss</I>&rdquo;,
&ldquo;<I>CCyymmdd</I><B>T</B><I>hh:mm:ss</I>&rdquo;,
or
&ldquo;<I>CCyy-mm-dd</I><B>T</B><I>hh:mm:ss</I>.&rdquo;
Note that only these four formats are accepted.
The command does <I>not</I> accept the full range of point-in-time
specifications specified in ISO8601.  Other formats can be recognized by
giving an explicit <B>-format</B> option to the <B>clock scan</B> command.
<P><DT><A NAME="M84"><I>relative time</I></A><DD>
A specification relative to the current time.  The format is <B>number
unit</B>. Acceptable units are <B>year</B>, <B>fortnight</B>,
<B>month</B>, <B>week</B>, <B>day</B>,
<B>hour</B>, <B>minute</B> (or <B>min</B>), and <B>second</B> (or <B>sec</B>).  The
unit can be specified as a singular or plural, as in <B>3 weeks</B>.
These modifiers may also be specified:
<B>tomorrow</B>, <B>yesterday</B>, <B>today</B>, <B>now</B>,
<B>last</B>, <B>this</B>, <B>next</B>, <B>ago</B>.
<P></DL>
<P>
The actual date is calculated according to the following steps.
<P>
First, any absolute date and/or time is processed and converted.
Using that time as the base, day-of-week specifications are added.
Next, relative specifications are used.  If a date or day is
specified, and no absolute or relative time is given, midnight is
used.  Finally, a correction is applied so that the correct hour of
the day is produced after allowing for daylight savings time
differences and the correct date is given when going from the end
of a long month to a short month.
<H3><A NAME="M85">SEE ALSO</A></H3>
<B><A HREF="../TclCmd/msgcat.htm">msgcat</A></B>
<H3><A NAME="M86">KEYWORDS</A></H3>
<A href="../Keywords/C.htm#clock">clock</A>, <A href="../Keywords/D.htm#date">date</A>, <A href="../Keywords/T.htm#time">time</A>
<H3><A NAME="M87">COPYRIGHT</A></H3>
Copyright &copy; 2004 Kevin B. Kenny &lt;kennykb@acm.org&gt;. All rights reserved.
<div class="copy">Copyright &copy; 2004 Kevin B. Kenny &lt;kennykb(at)acm.org&gt;. All rights reserved.
</div>
</BODY></HTML>
